<?php
/** @var string $sid */

//$game = new \main\game();
$player = $game->player_get_uinfo();//获取玩家信息
$tishi = '';

if ( !isset($arr_data->cmd2) ){
    $arr_data->cmd2 = 'nowmid';
}

if ($player->uhp <= 0) {
    $tishi = "<div class='tishi' >重伤，请治疗<br/></div>";
}

switch ($arr_data->cmd2){
    case 'gomid':
        if ( !isset($arr_data->gomid) ){
            $arr_data->gomid = $player->nowmid;
        }
        if ($player->uhp <= 0) {
            $arr_data->gomid = $game->player_go_re();//移动到复活点
            $map = $game->mid_get_info($arr_data->gomid);//获取地图信息
            break;
        }
        $game->player_gomid($arr_data->gomid);//移动
        $map = $game->mid_get_info($arr_data->gomid);//获取地图信息

        break;
    case 'gonowmid':
        $map =  $game->mid_get_info($player->nowmid);//获取地图信息
        break;
    case 'goremid':
        $arr_data->gomid = $game->player_go_re();//移动到复活点
        $map = $game->mid_get_info($arr_data->gomid);//获取地图信息
        break;
}

$player = $game->player_get_uinfo();//获取玩家信息

if (!$player->nowmid){//判断角色是否出现在非法地图
    $出生地 = $game->get_system_config("游戏","出生地");
    $game->player_update_game1('nowmid', $出生地);
    $player->nowmid = $出生地;

}

$map =  $game->mid_get_info($player->nowmid);//获取地图信息

$pvphtml = "[安]";
if ($map->ispvp){
    $pvphtml = "[PVP]";
}
$出口_上 = $game->mid_get_out_mup($map);
$出口_下 = $game->mid_get_out_mdown($map);
$出口_左 = $game->mid_get_out_mleft($map);
$出口_右 = $game->mid_get_out_mright($map);

$bosshtml = '';
if ($map){
    if (!$map->midinfo)
    $map->midinfo = $map->mname;
}


if ( $player->ispvp!=0 ){
    $pvper = $game->player_get_uinfo_uid($player->ispvp);
    $链接_还击 = $game->create_url_obj("cmd=pvp&cmd2=into_pvp&uid=$pvper->uid","还击");
    $tishi .= "$pvper->uname 正在攻击你：{$链接_还击->按钮短}<br/>";
}

if ($game->player_is_tupo() && $player->uexp >= $player->umaxexp){
    $链接_突破 = $game->create_url_obj("cmd=tupo&cmd2=tupo","突破");
    $tishi .=  "你即将需要突破,否则将不能获得经验:{$链接_突破->按钮短}";
}


$guaiwu_all = $game->mid_get_guaiwu_all($map->mid); //获取现有怪物
$nowdate = date('Y-m-d H:i:s');

$second=floor((strtotime($nowdate)-strtotime($map->mgtime))%86400);//获取刷新间隔
if ($second > $map->ms  && count($guaiwu_all)== 0 && $map->mgid){//刷新怪物

    $gw_arr = $game->mid_get_guaiwu_sys_all($map->mid);

    foreach ($gw_arr as $gid){

        $guaiwu = $game->gw_get_info_sys($gid);
        $gw_count = $game->mid_get_guaiwu_sys_num($map->mid , $gid );

        for ($n = 0 ; $n < $gw_count ; $n++) {
            $game->mid_add_gw($gid, $map->mid);
        }
    }
}

$udc_show_gw_ext_info=intval($game->get_system_config("怪物","1表示显示扩展信息"));
if($udc_show_gw_ext_info==1){
    $guaiwu_all = $game->mid_get_guaiwu_all_and_wounded($map->mid); //获取怪物 含被受伤的(当前sid)
}else{
    $guaiwu_all = $game->mid_get_guaiwu_all($map->mid); //获取现有怪物
}
$gwhtml = '';

for ($i = 0;$i<count($guaiwu_all);$i++){

    $gid = $guaiwu_all[$i]['id'];
    $gyid = $guaiwu_all[$i]['gyid'];

    if($udc_show_gw_ext_info==1){
        //$tmpExt='(#'.$gid;
        $tmpExt='';
        $ghp =intval($guaiwu_all[$i]['ghp']) ;
        $gmaxhp =intval($guaiwu_all[$i]['gmaxhp']) ;
        if($gmaxhp-$ghp>=$gmaxhp/10){
            if($gmaxhp-$ghp>=$gmaxhp/3){
                $tmpExt.='(重伤)';
            }else{
                $tmpExt.='(伤)';
            }
        }else{
            $tmpExt.='';
        }
        //$tmpExt.=')';
    }else{
        $tmpExt='';
    }
    $gwcmd = $game->create_url_obj("cmd=ginfo&gid={$gid}&gyid={$gyid}&nowmid=$player->nowmid","{$guaiwu_all[$i]['gname']}{$tmpExt}");
    $gwhtml .= $gwcmd->按钮短;
}

$array_player_online = $game->mid_get_player_online($player->nowmid);

$playerhtml = '';
if ($array_player_online){
    //var_dump($array_player_online);
    $nowdate = date('Y-m-d H:i:s');

    for ($i = 0; $i < count($array_player_online);$i++) {

        $player1 = (object)$array_player_online[$i];

        $cxtime = $player1->endtime;
        $cxuid = $player1->uid;
        $cxsid = $player1->sid;
        $cxuname = $player1->uname;

        $second = floor((strtotime($nowdate) - strtotime($cxtime)) % 86400);//获取刷新间隔

        if ($second > 300) {
            $game->player_update_sfzx_uid(0, $cxuid);
        } else {
            $clubp = $game->clubplayer_get_player_uid($cxuid);
            if ($clubp) {
                $club = $game->club_get_info($clubp->clubid);
                $club->clubname = "[$club->clubname]";
            } else {
                $club=(object)array('clubname'=>'');
            }
            $playercmd = $game->create_url_obj("cmd=otherzhuangtai&uid=$cxuid","{$变量_系统->颜色_亮橙色}{$club->clubname}{$变量_系统->颜色_颜色完}$cxuname");
            $playerhtml .= $playercmd->按钮短;
        }
    }
}


$npchtml='';

$task = $game->rw_player_get_all();
$rcrw = $game->rw_player_date_get_all();

for ($n=0 ; $n<count($rcrw) ; $n++){
    $rctask = $rcrw[$n];
    if ($rctask->data != date('d') ){
        $rwid = $rctask->rwid ;
        $game->rw_player_delete( $rwid);//删除日常任务 达到刷新效果
    }
}

if ($map->mnpc != ""){
    $cxnpcall = $game->mid_get_npc($map->mnpc);

    for ($i=0;$i < count($cxnpcall);$i++){
        $npc = $cxnpcall[$i];
        $nname = $npc->nname;
        $nid = $npc->id;
        $taskid = $npc->taskid;

        $taskarr = explode(',',$taskid);

        if ($taskid != ''){
            for ($l=0; $l<count($taskarr) ;$l++){
                $rw_sys =  $game->rw_get_sys($taskarr[$l]);
                $rw_player = $game->rw_player_get_info($taskarr[$l]);
                $lastrwid = $rw_sys->lastrwid;

                if ($rw_player){
                    if ($rw_player->rwzt == 2){
                        if ($rw_player->tijiao != $nid){
                            continue;
                        }


                        $npchtml .='<img src="./images/tan.gif" />';
                    }
                    continue;
                }else{

                    if ($rw_sys->chufa != $nid){
                        continue;
                    }

                    if ($rw_sys->rwlx == 3 && $rw_sys->lastrwid != -1){
                        $lastrw = $game->rw_player_get_info($rw_sys->lastrwid);
                        if (!$lastrw){
                            continue;
                        }elseif ($lastrw->rwzt != 3){
                            continue;
                        }
                    }
                    $npchtml .='<img src="./images/wen.gif" />';
                }

            }
        }
        $temp_链接_npc = $game->create_url_obj("cmd=npc&cmd2=npc&nid=$nid",$nname);
        $npchtml .= $temp_链接_npc->按钮短;
    }
}


$obj_liaotian_all = $game->liaotian_get_all(2);

$lthtml='';
if ($obj_liaotian_all){
    for ($i=0;$i < count($obj_liaotian_all);$i++){
        $ltObj = $obj_liaotian_all[count($obj_liaotian_all) - $i-1];

        $uname = $ltObj->name;
        $umsg = $ltObj->msg;
        $uid = $ltObj->uid;
        $date = $ltObj->date;

        $date = date_create($date);
        $date = date_format($date,'H:i:s');

        $ucmd = $game->create_url_obj( "cmd=otherzhuangtai&uid=$uid",$uname);
        if ($uid){
            $lthtml .="[公共][{$date}]{$ucmd->按钮短}:{$umsg}<br />";
        }else{
            $lthtml .="[公共][{$date}]<div class='hpys' style='display: inline'>{$uname}:</div>{$umsg}<br />";
        }

    }
}


$变量_地图 =(object) [
    "名称" => $map->mname,
    "属性" => $pvphtml,
    "地图信息" => $map->midinfo,
    "玩家_列表" => $playerhtml,
    "NPC_列表" => $npchtml,
    "怪物_列表" => "$gwhtml",
    "聊天_显示" => "<div id='ltmsg'>$lthtml</div>",
    "系统_提示" => $tishi,

    '链接_刷新' => $game->create_url_obj("cmd=mid&cmd2=gonowmid","刷新"),
    "链接_出口_上" => $出口_上,
    "链接_出口_下" => $出口_下,
    "链接_出口_左" => $出口_左,
    "链接_出口_右" => $出口_右,


];

$dis_mid = $game->dis_get('排版_地图');

eval("\$out_html = \"$dis_mid->dis_string\";");
$out_html = str_replace("<br/><br/>", "<br/>",$out_html);
$out_html = str_replace("<br/><br/>", "<br/>",$out_html);
$out_html = str_replace("</div><br/>", "</div>",$out_html);
echo $out_html;
//<!--.<a href="$cwcmd" >宠物</a>.-->


?>